//
//  PTOpenBluetooth.swift
//  PTWatch Watch App
//
//  Created by sc-chen on 2023/9/20.
//

import SwiftUI

struct PTOpenBluetooth: View {
    @State private var content_btn = "打开蓝牙"
    @State private var content_lb = "蓝牙已关闭"
    @State private var open = false
    
    @ObservedObject var bluetoothManager = PTBluetoothManager()
    
    @State private var isShowingHUD = false
    @State private var detailTxt = "不支持开发功能"
    
    var body: some View {
        /*ZStack {
            VStack {
                Button {
                    showBlueToothStatus()
                    showHud()
                } label: {
                    Text(content_btn)
                        .padding(EdgeInsets(top: 10, leading: 30, bottom: 10, trailing: 30))
                        .foregroundColor(.blue)
                        .overlay(
                            RoundedRectangle(cornerRadius: 10)
                                .stroke(Color.blue, lineWidth: 1)
                                .padding(.trailing,5)
                        )
                }.buttonStyle(.borderless)
                Text(content_lb)
                    .padding(EdgeInsets(top: 40, leading: 30, bottom: 10, trailing: 30))
                    .foregroundColor(.black)
                Spacer()
            }.padding()
            PTProgressHud(isPresented: $isShowingHUD, text: $detailTxt)
        }.onAppear(){
            showHud()
            DispatchQueue.main.asyncAfter(deadline: .now()+1){
                showBlueToothStatus()
                bluetoothManager.startScanning()
            }
        }*/
        
        Text("不支持打开蓝牙的开发功能")
    }
    
    private func showBlueToothStatus() {
        if self.bluetoothManager.isBluetoothOn {
            content_lb = "蓝牙已打开"
        } else {
            content_lb = "蓝牙已关闭"
        }
    }
    
    private func showHud() {
        isShowingHUD = true
        DispatchQueue.main.asyncAfter(deadline: .now()+2){
            isShowingHUD = false
        }
    }
}

struct PTOpenBluetooth_Previews: PreviewProvider {
    static var previews: some View {
        PTOpenBluetooth()
    }
}
